"use strict";
const electron = require("electron");
const path = require("path");
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
electron.app.commandLine.appendSwitch("disable-web-security");
electron.app.commandLine.appendSwitch("disable-features", "OutOfBlinkCors");
electron.app.commandLine.appendSwitch("--ignore-certificate-errors", "true");
let win = null;
const createWindow = async () => {
  win = new electron.BrowserWindow({
    title: "董员外",
    width: 1e3,
    height: 800,
    icon: path.join(__dirname, "../public/logo.ico"),
    webPreferences: {
      webSecurity: false,
      nodeIntegration: true,
      contextIsolation: true,
      webviewTag: true,
      preload: path.join(__dirname, "preload.js")
    }
  });
  if (process.env.VITE_DEV_SERVER_URL) {
    win.loadURL(process.env.VITE_DEV_SERVER_URL);
    win.webContents.openDevTools();
  } else {
    win.loadFile(path.join(__dirname, "../dist/index.html"));
  }
};
electron.app.whenReady().then(createWindow);
electron.app.on("window-all-closed", () => {
  electron.app.exit();
});
const selfWindws = async () => await Promise.all(
  electron.webContents.getAllWebContents().filter((item) => {
    const win2 = electron.BrowserWindow.fromWebContents(item);
    return win2 && win2.isVisible();
  }).map(async (item) => {
    const win2 = electron.BrowserWindow.fromWebContents(item);
    const thumbnail = await (win2 == null ? void 0 : win2.capturePage());
    return {
      name: (win2 == null ? void 0 : win2.getTitle()) + (item.devToolsWebContents === null ? "" : "-dev"),
      // 给dev窗口加上后缀
      id: win2 == null ? void 0 : win2.getMediaSourceId(),
      thumbnail,
      display_id: "",
      appIcon: null
    };
  })
);
electron.ipcMain.handle(
  "ev:send-desktop-capturer_source",
  async (_event, _args) => {
    return [
      ...await electron.desktopCapturer.getSources({ types: ["window", "screen"] }),
      ...await selfWindws()
    ];
  }
);
electron.ipcMain.on("consolelog", () => {
  console.log("打印 this is 111111");
});
electron.ipcMain.on("consolelog_2", (event, data) => {
  console.log("打印 this is ", data);
});
electron.ipcMain.on("consolelog_3", (event, data) => {
  console.log("打印 this is ", data);
});
